package com.ooono.factorytest.items;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.ooono.factorytest.R;
import com.ooono.factorytest.base.BaseActivity;

public class DisplayTestActivity extends BaseActivity {

    public static final String KEY = "display";

    private FrameLayout mBgView;
    FrameLayout mBlackView;
    TextView mTipsTv;
    private int mClickCnt = 0;

    @Override
    public int getContentLayout() {
        return R.layout.content_display_test;
    }

    @Override
    public void initViews() {
        mBgView = findViewById(R.id.fl_bg);
        mBlackView = findViewById(R.id.view_black);
        mTipsTv = findViewById(R.id.tv_tips);
        mBgView.setOnClickListener(view -> {
            switch (mClickCnt) {
                case 0:
                    update(getString(R.string.lcd_test_click), 0xffffffff, 0xffff0000);
                    break;
                case 1:
                    update(getString(R.string.lcd_test_click), 0xffffffff, 0xff00ff00);
                    break;
                case 2:
                    update(getString(R.string.lcd_test_click), 0xffffffff, 0xff0000ff);
                    break;
                case 3:
                    update(getString(R.string.lcd_test_click), 0xffffffff, 0xffffff00);
                    break;
                case 4:
                    update(getString(R.string.lcd_test_click), 0xffffffff, 0xffa9a9a9);
                    break;
                case 5:
                    update(getString(R.string.lcd_test_click), 0xffffffff, 0xff000000);
                    break;
                case 6:
                    mBlackView.setVisibility(View.VISIBLE);
                    update(getString(R.string.lcd_test_click), 0xffffffff, 0xffa9a9a9);
                    break;
                case 7:
                    mBlackView.setVisibility(View.INVISIBLE);
                    update(getString(R.string.lcd_test_prompt), 0xff000000, getResources().getColor(R.color.white, null));
                    break;
                default:
                    break;
            }
            if (mClickCnt != 7) {
                mClickCnt++;
                bottomButtonCl.setVisibility(View.GONE);
            } else {
                bottomButtonCl.setVisibility(View.VISIBLE);
            }
        });
    }

    private void update(String tips, int textColor, int bgColor) {
        mTipsTv.setText(tips);
        mTipsTv.setTextColor(textColor);
        mBgView.setBackgroundColor(bgColor);
    }

    @Override
    public int getTestTitle() {
        return -1;
    }

    @Override
    public String getTestKey() {
        return KEY;
    }

    @Override
    protected void onResume() {
        super.onResume();
        bottomButtonCl.setVisibility(View.GONE);
    }

    @Override
    protected void onStop() {
        super.onStop();
        bottomButtonCl.setVisibility(View.VISIBLE);
    }
}
